package com.tanhua.server.config;

import com.tanhua.server.interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Bean
    public Freezingspeech getredis() {
        return new Freezingspeech();
    }

    @Bean
    public Freezedynamic getrediss() {
        return new Freezedynamic();
    }

    @Bean
    public ActiveTime getrediis() {
        return new ActiveTime();
    }

    @Autowired
    private RedisCacheInterceptor redisCacheInterceptor;

    @Autowired
    private UserTokenInterceptor userTokenInterceptor;

    @Autowired
    private Freezingspeech freezingspeech;

    @Autowired
    private Freezedynamic freezedynamic;

    @Autowired
    private ActiveTime activeTime;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ArrayList<String> speech = new ArrayList<>();
        speech.add("/comments");
        speech.add("/smallVideos/{id}/comments");
        ArrayList<String> dynamic = new ArrayList<>();
        dynamic.add("/movements");
        dynamic.add("/smallVideos");
        //考虑拦截器的顺序
        registry.addInterceptor(this.userTokenInterceptor).addPathPatterns("/**");
        registry.addInterceptor(this.redisCacheInterceptor).addPathPatterns("/**");
        registry.addInterceptor(this.freezingspeech).addPathPatterns(speech);
        registry.addInterceptor(this.freezedynamic).addPathPatterns(dynamic);
        registry.addInterceptor(this.activeTime).addPathPatterns("/**");
    }
}